import request from '@/api/index'

const state = {
    //登录状态
    isLogin: false,
    //播放状态
    isPlay: false
}

const mutations = {
    changeLogin: (state, payload) => {
        state.isLogin = payload
    },
    changePlay: (state, payload) => {
        state.isPlay = payload
    }
}
const actions = {
    //获取登录状态,登录状态接口刷新存在延迟，所以有时不能及时获取到登录的状态
    async getLoginState({ commit, dispatch }) {
        const res = await request("/login/status")
        if (res.data.profile !== null) {
            //获取账户信息
            dispatch('getAccount')
            commit("changeLogin", true)
        } else
            commit("changeLogin", false)
    },
}




export default {
    state,
    mutations,
    actions,
}